// MapChart.cpp: implementation of the CMapChart class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PathTreeNode.h"
#include "MapChart.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMapChart::CMapChart()
{

}

CMapChart::~CMapChart()
{

}

void CMapChart::Init(HDC hDC, CPathTreeNode* pTreeNode)
{
	if (NULL == pTreeNode)
	{
		return;
	}
	m_hDC = hDC;
	m_pTreeNode = pTreeNode;
	m_rect.X = 0;
	m_rect.Y = 0;
	m_rect.Width = 200;
	m_rect.Height = 200;
}

void CMapChart::DrawCircle()
{
	ASSERT(NULL != m_pTreeNode);
	Graphics graphics(m_hDC);

	REAL nWidth = 20;
	Pen penArc(Color::Red, nWidth);
	Pen penArc2(Color::Green, nWidth);
	Pen* pen[2] = {&penArc, &penArc2};
	REAL startDig(0), sweepDig(0);

	//
	int nSize = m_pTreeNode->GetChildNum();
	int i,j;
	long double l64Total = m_pTreeNode->GetLength();
	if (l64Total == 0)
	{
		Pen penWhite(Color::White, nWidth);
		startDig = 0.0f;
		sweepDig = 360.0f;
		graphics.DrawArc(&penWhite, m_rect, startDig, sweepDig);
	}
	else
	{
		for (i=0,j=0; i<nSize; i++,j++)
		{
			long double l64child = m_pTreeNode->GetChild(i)->GetLength();
			sweepDig = ((l64child/l64Total))*360.0f;
			if (j>1)
			{
				j=0;
			}
			graphics.DrawArc(pen[j], m_rect, startDig, sweepDig);
			startDig = sweepDig;
		}
	}

}
